<?php
namespace app\tour\model;

use think\Db;
use think\Model;
use think\Session;

class Order extends Model
{

    public static function orderList($field, $where, $startrow = 0, $pageSize = 0, $isCount = false)
    {

        $tour_id = Session::get('tour_id');

        $query = Db::name('tour_order')->alias('t1')
            ->field('t1.*,t2.create_time as time,t3.admin_rename')
            ->join('order_cancel t2', 't1.order_id=t2.order_id', 'left')
            ->join('tour_admin t3', 't2.cancel_id = t3.t_admin_id', 'left')->where('t1.tour_id', $tour_id)
            ->where('t1.is_del', 0)
            ->where($where);

        if ($isCount) {

            return $query->count();

        }

        if ($pageSize) {

            $res = $query
                ->order('order_id desc')
                ->limit($startrow, $pageSize)
                ->select();
            foreach ($res as $k => $v) {
                $res[$k]['ticket_date'] = date('Y-m-d', $v['ticket_date']);
                $res[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
            }
            return $res;

        }

        $res = $query->select();
        foreach ($res as $k => $v) {
            $res[$k]['ticket_date'] = date('Y-m-d', $v['ticket_date']);
            $res[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
        }
        return $res;

    }
}
